<?php

namespace app\marketing\model;

use app\BaseModel;
use think\facade\Db;

/**
 * @mixin think\Model
 */
class PosterType extends BaseModel
{
    protected $name = 'longbing_card_poster_type';
    protected $pk = 'id';

    public function listPosterTypes($filter ,$page_config = ['page' => 1 ,'page_count' => 20]) {
        $result = $this->where($filter)
                       ->page($page_config['page'] ,$page_config['page_count'])
                       ->order('top', 'desc')
                       ->select();

        return $result;
    }

    public function listPosterTypesCount($filter) {
        $result = $this->where($filter)->count();
        return $result;
    }

    public function createPosterType($data)
    {
        $time = time();
        $data['create_time'] = $time;
        $data['update_time'] = $time;
        $res = $this->insert($data);
        return $res;
    }

    public function updatePosterType($where,$data){
        $data['update_time'] = time();
        $res = $this->where($where)->strict(false)->update($data);
        return $res;
    }


    public function getPosterType($where)
    {
        $data = $this->where($where)->find();
        return !empty($data)?$data->toArray():$data;
    }



}
